﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace community
{
    public partial class familymove : Form
    {
        public static string XSQ;//新社区
        public familymove()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox1.Text =Convert.ToString( family.datagridviewSQMC);
            textBox2.Text = Convert.ToString(family.datagridviewHZXM);
            textBox3.Text = Convert.ToString(family.datagridviewJTBH);
        }

        private void textBox4_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = true;
            SqlConnection  cn = new SqlConnection(SQL.conStr);
            cn.Open();
            string sqlStr = "select COMMUNITYNAME_VCHR as 社区名称  from t_cs_community  where  CURRENTCS_INT=1";
            SqlDataAdapter dt = new SqlDataAdapter(sqlStr, cn);
            DataSet ds = new DataSet();
            dt.Fill(ds);
            this.dataGridView1.DataSource = ds.Tables[0];
            dataGridView1.ColumnHeadersHeight = 39;
            dataGridView1.Columns[0].Width = 150;
            cn.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                //textbox1 .Text = datagridview1.Rows[e.RowIndex].Cells[0].Value.ToString();
                //textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                //communityBH = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString();
                //communityYZBM = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString();
                if (textBox1.Text != null) dataGridView1.Visible = false;
                //stat = 1;
                //textBox1.Focus();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "")
            {
                MessageBox.Show("请输入新社区", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            if (textBox1.Text == textBox4.Text)
            {
                MessageBox.Show("新旧社区相同，请重新输入新社区", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            XSQ = Convert.ToString(textBox4.Text.Trim());
            string str = "update T_CS_FAMILYRECORD set COMMUNITYNAME_CHR='" + Convert.ToString(textBox4.Text.Trim()) + "' where FAMILYCORD_CHR='"+Convert.ToString(textBox3.Text.Trim())+"'";
            SqlConnection cn = new SqlConnection(SQL.conStr);
            cn.Open();
            SqlCommand cm = new SqlCommand(str, cn);
            cm.ExecuteNonQuery();
            cn.Close();
            MessageBox.Show("修改家庭所属社区成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
    }
}
